package com.ayit.car.controller.car;

import com.ayit.car.common.result.PageResult;
import com.ayit.car.common.result.Result;
import com.ayit.car.pojo.Brands;
import com.ayit.car.pojo.dto.BrandPageQueryDTO;
import com.ayit.car.service.BrandsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/car/brands")
@Slf4j
@Api(tags = "品牌管理")
public class BrandsController {

    @Autowired
    private BrandsService brandsService;

    /**
     * 查询汽车品牌列表
     */
    @GetMapping("/page")
    @ApiOperation(value = "分页查询品牌列表")
    public Result<PageResult> list(BrandPageQueryDTO brandPageQueryDTO) {
        log.info("查询汽车品牌列表: {}", brandPageQueryDTO); // 使用{}进行格式化输出
        PageResult pageResult = brandsService.pageQuery(brandPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 获取汽车品牌详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取汽车品牌详细信息")
    public Result getInfo(@PathVariable("id") Long id) {
        log.info("获取汽车品牌详细信息: {}", id);
        Brands brands = brandsService.selectBrandsById(id);
        return Result.success(brands);
    }

    /**
     * 新增汽车品牌
     */
    @ApiOperation(value = "新增汽车品牌")
    @PostMapping
    public Result add(@RequestBody Brands brands) {
        log.info("新增汽车品牌: {}", brands);
        brandsService.insertBrands(brands);
        return Result.success();
    }

    /**
     * 修改汽车品牌
     */
    @ApiOperation(value = "修改汽车品牌")
    @PutMapping
    public Result edit(@RequestBody Brands brands) {
        log.info("修改汽车品牌: {}", brands);
        brandsService.updateBrands(brands);
        return Result.success();
    }


    /**
     * 批量删除汽车品牌
     */
    @ApiOperation(value = "删除汽车品牌")
    @DeleteMapping("/{ids}")
    public Result remove(@PathVariable List<Long> ids) {
        log.info("删除汽车品牌: {}", ids.toString());
        brandsService.deleteBrandsByIds(ids);
        return Result.success();
    }
}
